package com.zzty.txj1.controller;

import com.zzty.txj1.entity.SelfExam;
import com.zzty.txj1.entity.TeamExam;
import com.zzty.txj1.service.SelfExamService;
import com.zzty.txj1.service.TeamExamService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/setWork")
public class SetWorkController {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SetWorkController.class);
    @Autowired
    TeamExamService teamExamService;

    @Autowired
    SelfExamService selfExamService;

    @RequestMapping("/checkTeamExamDate/{date}")
    public Map<String, String> checkDateFromTeamExam(@PathVariable("date") String date) {
        System.out.println("date====="+date);
        System.out.println("checkDateFromTeamExam======");
        Map<String, String> map = new HashMap<>();
        Integer count = teamExamService.checkDate(date);
        logger.info("TeamExam count===" + count);
        if (count == 0) {
            map.put("result", "success");
        } else {
            map.put("result", "false");
        }
        return map;
    }

    @RequestMapping(value = "/addTeamExamQuestion", method = RequestMethod.POST)
    public Map<String, Integer> addTeamExamQuestion(TeamExam teamExam) {
        System.out.println("addTeamExamQuestion!!!!!!!!!!!!!   teamExam: " + teamExam.toString());
        Map<String, Integer> map = new HashMap<>();
        Integer count = teamExamService.addTeamExamQuestion(teamExam);
        System.out.println("ateq count: " + count);
        if (count == 1) {
            map.put("result", 1);
        } else {
            map.put("result", 0);
        }
        return map;
    }

    @RequestMapping("/checkSelfExamDate/{date}")
    public Map<String, String> checkDateFromSelfExam(@PathVariable("date") String date) {
        Map<String, String> map = new HashMap<>();
        Integer count = selfExamService.checkDate(date);
        logger.info("SelfExam count===" + count);
        if (count == 0) {
            map.put("result", "success");
        } else {
            map.put("result", "false");
        }
        return map;
    }

    @RequestMapping(value = "/addSelfExamQuestion", method = RequestMethod.POST)
    public Map<String, Integer> addSelfExamQuestion(SelfExam selfExam) {
        logger.info("addSelfExamQuestion!!!!!!!!!!!!!   selfExam: " + selfExam.toString());
        System.out.println("addSelfExamQuestion!!!!!!!!!!!!!   selfExam: " + selfExam.toString());
        Map<String, Integer> map = new HashMap<>();
        Integer count = selfExamService.addSelfExamQuestion(selfExam);
        System.out.println("aseq count: " + count);
        if (count == 1) {
            map.put("result", 1);
        } else {
            map.put("result", 0);
        }
        return map;
    }
}
